package com.xjtu.mybatisplus.web.controller;

import com.xjtu.mybatisplus.common.result.PageResult;
import com.xjtu.mybatisplus.model.vo.SubscribeVo;
import com.xjtu.mybatisplus.service.SubscribeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xjtu.mybatisplus.common.JsonResponse;
import com.xjtu.mybatisplus.model.domain.Subscribe;

import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lsong
 * @since 2023-12-27
 * @version v1.0
 */
@RestController
@RequestMapping("/api/subscribe")
@Api(tags = "订阅管理")
public class SubscribeController {

    private final Logger logger = LoggerFactory.getLogger( SubscribeController.class );

    @Autowired
    private SubscribeService subscribeService;

    @GetMapping
    @ApiOperation("用户获取栏目订阅情况")
    public JsonResponse getSubStatus(@RequestParam(required = true)Long userId, @RequestParam(required = true)Long categoryId){
        return subscribeService.getStatus(userId, categoryId);
    }

    @PutMapping
    @ApiOperation("用户设置订阅/取消订阅")
    public JsonResponse setSubStatus(@RequestParam(required = true)Long userId, @RequestParam(required = true)Long categoryId,@RequestParam(required = true)boolean status){
        return subscribeService.setStatus(userId, categoryId, status);
    }

    @GetMapping("list")
    @ApiOperation("用户获取订阅列表")
    public JsonResponse<List<SubscribeVo>> getSubList(@RequestParam(required = true) Long userId) {
        return subscribeService.getList(userId);
    }
//    @Autowired
//    private SubscribeService subscribeService;
//
//    /**
//    * 描述：根据Id 查询
//    *
//    */
//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
//    @ResponseBody
//    public JsonResponse getById(@PathVariable("id") Long id)throws Exception {
//        Subscribe  subscribe =  subscribeService.getById(id);
//        return JsonResponse.success(subscribe);
//    }
//
//    /**
//    * 描述：根据Id删除
//    *
//    */
//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//    @ResponseBody
//    public JsonResponse deleteById(@PathVariable("id") Long id) throws Exception {
//        subscribeService.removeById(id);
//        return JsonResponse.success(null);
//    }
//
//
//    /**
//    * 描述：根据Id 更新
//    *
//    */
//    @RequestMapping(value = "", method = RequestMethod.PUT)
//    @ResponseBody
//    public JsonResponse updateSubscribe(Subscribe  subscribe) throws Exception {
//        subscribeService.updateById(subscribe);
//        return JsonResponse.success(null);
//    }
//
//
//    /**
//    * 描述:创建Subscribe
//    *
//    */
//    @RequestMapping(value = "", method = RequestMethod.POST)
//    @ResponseBody
//    public JsonResponse create(Subscribe  subscribe) throws Exception {
//        subscribeService.save(subscribe);
//        return JsonResponse.success(null);
//    }
}

